var e = require;
var t = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
var n = e("BaseModuleUI"),
    a = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("AssetsManager"),
    s = e("AudioManager"),
    l = e("Game"),
    c = e("role_effects_info"),
    d = e("role_node"),
    h = cc._decorator,
    _ = h.ccclass,
    u = h.property,
    p = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.role_name_label = null),
                (t.my_node = null),
                (t.other_node = null),
                (t.enemy_node = null),
                (t.level_label = null),
                (t.exp_node = null),
                (t.role_hp_node = null),
                (t.level_num = 1),
                (t.exp_num = 0),
                (t.role_node_item = null),
                (t.have_hp = 0),
                (t.now_have_hp = 0),
                (t.role_info = null),
                (t.is_die = !1),
                (t.player_index = 0),
                (t.hero_kill_id = [-1, -1]),
                t
            );
        }
        return (
            __extends(t, e),
            (t.prototype.InfoInit = function (e, t) {
                (this.player_index = e), (this.role_node_item = t), (this.hero_kill_id = [-1, -1]);
                var o = i.GlobalParams.MatchGamePlayer[e];
                (this.role_name_label.string = o.name),
                    (this.role_name_label.node.color =
                        e == i.GlobalParams.MatchMyIndex ? cc.color(20, 255, 50) : cc.color(255, 255, 255)),
                    (this.my_node.active = this.other_node.active = this.enemy_node.active = !1),
                    e == i.GlobalParams.MatchMyIndex
                        ? ((this.role_hp_node = this.my_node), this.addRoleEffects(l.RoleEffectType.my_birth_light))
                        : e % 2 == i.GlobalParams.MatchMyIndex % 2
                        ? ((this.role_hp_node = this.other_node),
                          this.addRoleEffects(l.RoleEffectType.other_birth_light))
                        : (this.role_hp_node = this.enemy_node),
                    (this.role_hp_node.active = !0),
                    (this.role_hp_node.width = 125),
                    (this.level_num = o.level),
                    (this.exp_num = o.exp_num),
                    (this.role_info = this.role_node_item.getComponent(d.default).role_info),
                    this.getPlayerHp(),
                    this.showPlayerLevel();
            }),
            (t.prototype.addEvent = function () {
                this.attachEvent(a.default.SEND_UPDATE_MATCH_PLAYER_INFO, this.showMatchPlayerInfo, this),
                    this.attachEvent(a.default.SEND_PLAYER_LEVEL_UP_INFO, this.playerLevelUp, this),
                    this.attachEvent(a.default.SEND_UPDATE_BUY_EQUIP_NEW_ADD_INFO, this.updatePlayerHp, this);
            }),
            (t.prototype.showMatchPlayerInfo = function () {
                var e = i.GlobalParams.MatchGamePlayer[this.player_index];
                (this.level_num = e.level), (this.exp_num = e.exp_num), this.showPlayerLevel();
            }),
            (t.prototype.playerLevelUp = function (e, t) {
                t == this.player_index &&
                    (this.addRoleEffects(l.RoleEffectType.level_up),
                    this.player_index == i.GlobalParams.MatchMyIndex && s.default.getInstance().playFx("level_up"),
                    this.showMatchPlayerInfo(),
                    this.getPlayerHp(),
                    (this.role_hp_node.width = 125));
            }),
            (t.prototype.showPlayerLevel = function () {
                (this.exp_node.width = (125 * this.exp_num) / l.default.level_exp[this.level_num - 1]),
                    (this.level_label.string = "" + this.level_num);
            }),
            (t.prototype.getPlayerHp = function () {
                (this.have_hp =
                    i.GlobalParams.GamePlayerInfo[this.player_index].hp +
                    i.GlobalParams.BuyEquipInfo[this.player_index].hp),
                    (this.now_have_hp = this.have_hp);
            }),
            (t.prototype.updatePlayerHp = function (e, t) {
                if (t == this.player_index) {
                    var o =
                            i.GlobalParams.GamePlayerInfo[this.player_index].hp +
                            i.GlobalParams.BuyEquipInfo[this.player_index].hp,
                        n = o - this.have_hp;
                    (this.now_have_hp = this.now_have_hp + n < 10 ? 10 : this.now_have_hp + n),
                        (this.have_hp =
                            o +
                            i.GlobalParams.BuyEquipInfo[this.player_index].die_up_hp *
                                i.GlobalParams.MatchGamePlayer[this.player_index].kill_info[1]),
                        (this.role_hp_node.width = (125 * this.now_have_hp) / this.have_hp);
                }
            }),
            (t.prototype.playerSkillAddHp = function () {
                this.setRoleAddHp(0.2 * this.have_hp);
            }),
            (t.prototype.getRoleHpPercent = function () {
                return (this.now_have_hp / this.have_hp) * 100;
            }),
            (t.prototype.getHpNotFull = function () {
                return this.now_have_hp < this.have_hp;
            }),
            (t.prototype.setRoleAddHp = function (e) {
                (e = Number(e.toFixed())),
                    (this.now_have_hp += e),
                    this.now_have_hp >= this.have_hp
                        ? (this.now_have_hp = this.have_hp)
                        : this.emitEvent(a.default.SEND_SHOW_BE_HIT_INFO, {
                              attack: e,
                              my_team: 2,
                              end_pos: cc.v2(this.node.getPosition().x, this.node.getPosition().y)
                          }),
                    (this.role_hp_node.width = (125 * this.now_have_hp) / this.have_hp);
            }),
            (t.prototype.roleSkillAddHp = function (e) {
                var t = this.have_hp * e;
                this.setRoleAddHp(t);
            }),
            (t.prototype.roleBeHit = function (e, t) {
                var o = this;
                this.is_die ||
                    ((this.now_have_hp -= e),
                    this.emitEvent(a.default.SEND_SHOW_BE_HIT_INFO, {
                        attack: e,
                        my_team: this.player_index % 2 == 0 ? 0 : 1,
                        end_pos: cc.v2(this.node.getPosition().x, this.node.getPosition().y)
                    }),
                    this.hero_kill_id[0] != t &&
                        ((this.hero_kill_id[1] = this.hero_kill_id[0]),
                        (this.hero_kill_id[0] = t),
                        this.unschedule(this.clearHelpKillInfo),
                        this.scheduleOnce(this.clearHelpKillInfo, 3)),
                    (this.now_have_hp = this.now_have_hp < 0 ? 0 : this.now_have_hp),
                    (this.role_hp_node.width = (125 * this.now_have_hp) / this.have_hp),
                    this.now_have_hp <= 0 &&
                        !this.is_die &&
                        ((this.is_die = !0),
                        this.role_node_item.getComponent(d.default).showRoleDeath(),
                        this.addRoleEffects(l.RoleEffectType.coin),
                        this.scheduleOnce(function () {
                            var e = i.GlobalParams.MatchGamePlayer[o.player_index],
                                n = {role_index: o.player_index, cound_down: 10 * (e.level + e.kill_info[1])};
                            i.GlobalParams.PlayingRoleDie.push(n),
                                o.emitEvent(a.default.SEND_ROLE_BE_KILL_INFO, {
                                    kill: t,
                                    be_kill: o.player_index,
                                    team: o.player_index % 2 == 0 ? l.TeamInfo.left_team : l.TeamInfo.right_team,
                                    help_kill: o.hero_kill_id[1]
                                }),
                                o.node.destroy();
                        }, 0.01)));
            }),
            (t.prototype.clearHelpKillInfo = function () {
                this.hero_kill_id[1] = -1;
            }),
            (t.prototype.playerBeLight = function (e) {
                var t = this,
                    o = 0.05 * this.have_hp;
                this.addRoleEffects(l.RoleEffectType.fill),
                    this.roleBeHit(o, e),
                    this.schedule(
                        function () {
                            t.roleBeHit(o, e);
                        },
                        0.5,
                        2
                    );
            }),
            (t.prototype.addRoleEffects = function (e) {
                var t = cc.instantiate(r.default.getInstance().getFightPrefab("role_effects"));
                t.getComponent(c.default).showEffectInfo(e), t.setParent(this.role_node_item);
            }),
            __decorate([u(cc.Label)], t.prototype, "role_name_label", void 0),
            __decorate([u(cc.Node)], t.prototype, "my_node", void 0),
            __decorate([u(cc.Node)], t.prototype, "other_node", void 0),
            __decorate([u(cc.Node)], t.prototype, "enemy_node", void 0),
            __decorate([u(cc.Label)], t.prototype, "level_label", void 0),
            __decorate([u(cc.Node)], t.prototype, "exp_node", void 0),
            __decorate([_], t)
        );
    })(n.default);
o.default = p;
